package edu.ptu.acl.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import edu.ptu.acl.common.ResultVO;
import edu.ptu.acl.dto.param.IdListParam;
import edu.ptu.acl.entity.RoleAcl;
import edu.ptu.acl.service.IAclService;
import edu.ptu.acl.service.IRoleAclService;
import edu.ptu.acl.service.impl.RoleAclServiceImpl;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author LinJC
 * @since 2022-03-15
 */
@RestController
@RequestMapping("/roleAcl")
public class RoleAclController {

    @Resource
    private IRoleAclService roleAclService;

    //角色权限树形结构获取
    @GetMapping("/getRoleAclTree/{roleId}")
    public ResultVO getRoleAclTree(@PathVariable Long roleId){
        HashMap<String, Object> result = roleAclService.getRoleAclTree(roleId);
        return ResultVO.success(result);
    }

    //编辑角色权限关系
    @PutMapping("/updateRoleAcl/{roleId}")
    public ResultVO updateRoleAcl(@PathVariable Long roleId, @RequestBody IdListParam idListParam){
       roleAclService.updateRoleAcl(roleId, Arrays.asList(idListParam.getIds()));

        return ResultVO.success();
    }

}
